package com.situ.student.controller;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginFilter implements Filter {

	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		// 判断有没有登录
		// 没有登录，重定向到登录界面
		// 登录成功，chaing.doFilter
		HttpServletRequest httpServletRequest = (HttpServletRequest) request;
		HttpServletResponse httpServletResponse = (HttpServletResponse) response;
		String uri = httpServletRequest.getRequestURI();
		String servletpath = httpServletRequest.getServletPath();
		System.out.println("uri:" + uri);
		System.out.println("servletpath:" + servletpath);
		int lastIndex = servletpath.lastIndexOf(".");
		String extension = "";
		if (lastIndex != -1) {
			extension = servletpath.substring("lastIndex");
		}
		chain.doFilter(request, response);

	}

	public LoginFilter() {
	}

	public void destroy() {
	}

	public void init(FilterConfig fConfig) throws ServletException {
		// TODO Auto-generated method stub
	}

}
